/**
 * @author behrooz mahasseni
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details 
 * @file Main.java
 * @project edu.osu.intelligentagents
 */
package edu.osu.intelligentagents.assignment3;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import edu.osu.intelligentagents.common.Bandit;

public class Main {
	public static void main(String[] args) {
		Bandit bandit = new Bandit("data_assignment3" + File.separator
				+ "bandit3.txt");
		System.out.println(bandit.getArms().size());
		IncrementalUnifrom incrementalUniform = new IncrementalUnifrom(bandit);
		UCB ucb = new UCB(bandit);
		EpsilonGreedy epsilonGreedy1 = new EpsilonGreedy(bandit, 0.5f);
		EpsilonGreedy epsilonGreedy2 = new EpsilonGreedy(bandit, 0.8f);
		BufferedWriter bufferedWriter1, bufferedWriter2;
		try {
			bufferedWriter1 = new BufferedWriter(new FileWriter(new File(
					"b3_output_cumulative2.csv")));
			bufferedWriter2 = new BufferedWriter(new FileWriter(new File(
					"b3_output_simple.csv")));
			int N = 1000;
			int T = 100;
			for (int t = 0; t < T; t++) {
				System.out.println("t = " + t);
				long begin = System.currentTimeMillis();
				incrementalUniform.selectArm(N);
				ucb.selectArm(N);
				epsilonGreedy1.selectArm(N);
				epsilonGreedy2.selectArm(N);
				long end = System.currentTimeMillis();
				System.out.println("Duration of the iteration : "
						+ (end - begin));
			}
			bufferedWriter1
					.write("n,incremental, ucb, e-greedy,e-greedy(0.8)\n");

			bufferedWriter2
					.write("n,incremental, ucb, e-greedy(0.5), e-greedy(0.8)\n");

			for (int n = 0; n < incrementalUniform.averageCumulativeRegret
					.size(); n++) {
				bufferedWriter1.write(n + ","
						+ (incrementalUniform.averageCumulativeRegret.get(n))
						+ "," + (ucb.averageCumulativeRegret.get(n)) + ","
						+ (epsilonGreedy1.averageCumulativeRegret.get(n)) + ","
						+ (epsilonGreedy2.averageCumulativeRegret.get(n))
						+ '\n');

				bufferedWriter2.write(n + ","
						+ (incrementalUniform.averageSimpleRegret.get(n)) + ","
						+ (ucb.averageSimpleRegret.get(n)) + ","
						+ (epsilonGreedy1.averageSimpleRegret.get(n)) + ","
						+ (epsilonGreedy2.averageSimpleRegret.get(n)) + '\n');
			}
			bufferedWriter1.close();
			bufferedWriter2.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
